<%@ page import="com.hf.constant.OrderLunchConst"%>
<%@ page import="com.hf.fetch.FetchGroup"%>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="layout" content="mainUser">
<g:set var="entityName"
	value="${message(code: 'user.label', default: 'User')}" />
<title><g:message code="default.create.label"
		args="[entityName]" /></title>
</head>
<body id="body">
	<a href="#create-user" class="skip" tabindex="-1"><g:message
			code="default.link.skip.label" default="Skip to content&hellip;" /></a>
	<div class="nav" role="navigation">
		<ul>
			<li><a class="home" href="${createLink(uri: '/')}"><g:message
						code="default.home.label" /></a></li>
		</ul>
	</div>
	<div id="create-user" class="content scaffold-create" role="main">
		<h1>
			<g:message code="default.create.label" args="[entityName]" />
		</h1>
		<g:if test="${flash.message}">
			<div class="message" role="status">
				${flash.message}
			</div>
		</g:if>
		<g:hasErrors bean="${userInstance}">
			<ul class="errors" role="alert">
				<g:eachError bean="${userInstance}" var="error">
					<li
						<g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
							error="${error}" /></li>
				</g:eachError>
			</ul>
		</g:hasErrors>
		<g:form action="register">
			<fieldset class="form">
				<g:link controller="fileManager" action="downloadFile">Download Guide Document</g:link>
				<div class="fieldcontain">
					<label for="name">Name <span class="required">*</span></label>
					<g:textField required="true" name="name" value="${user?.name}" />
					example : fang.hao
					<g:hasErrors bean="${user}" field="name">
						<p class="error">
							<g:fieldError bean="${user}" field="name" />
						</p>
					</g:hasErrors>
				</div>
				<div class="fieldcontain">
					<label for="email">Email<span class="required">*</span></label>
					<g:textField name="email" readonly="true" value="${params?.email}" />
					auto complete : name + ‘@software.dell.com’
					<g:hasErrors bean="${user}" field="email">
						<p class="error">
							<g:fieldError bean="${user}" field="email" />
						</p>
					</g:hasErrors>
				</div>
				<div class="fieldcontain">
					<label for="code">Code<span class="required">*</span></label>
					<g:textField required="true" name="code" value="${params?.code}" />
					<button name="getCode" _action="getCode">Get code to validate email</button>
					<g:hasErrors bean="${user}" field="code">
						<p class="error">
							<g:fieldError bean="${user}" field="code" />
						</p>
					</g:hasErrors>
				</div>
				<div class="fieldcontain">
					<label for=fetchGroup>Fetch Group<span class="required">*</span></label>
					<g:select id="fetchGroup" name="fetchGroup.id"
						from="${com.hf.fetch.FetchGroup.list(sort:'name')}"
						optionKey="id"
						value="${FetchGroup.findByName(OrderLunchConst.TEMP_GROUP)?.id}"/>
				</div>
				<div class="fieldcontain">
					<label for="password">Password <span class="required">*</span></label>
					<g:passwordField required="true" name="password"
						value="${user?.password}" />
					<g:hasErrors bean="${user}" field="password">
						<p class="error">
							<g:fieldError bean="${user}" field="password" />
						</p>
					</g:hasErrors>
				</div>
				<div class="fieldcontain">
					<label for="confirm">Confirm Password <span
						class="required">*</span></label>
					<g:passwordField required="true" name="confirm"
						value="${params?.confirm}" />
					<g:hasErrors bean="${user}" field="confirm">
						<p class="error">
							<g:fieldError bean="${user}" field="confirm" />
						</p>
					</g:hasErrors>
				</div>
			</fieldset>
			<div align="center">
				<g:submitButton class="btn" name="register" value="Register" />
			</div>
			<jq:jquery>
            	$("#name").change(function() {
            		var name = $(this).val();
            		$("#email").val(name + "@software.dell.com");
            	});
            	$('[_action="getCode"]').live('click',function(e){
					e.preventDefault();
					if ($('#name').val()=="") {
						alert('Enter your name first!');
						return;
					}
					var form = $(this).closest('form');
					var data = form.serialize();
					$.ajax({
						type:'POST',
						url: '/orderLunch/orderUser/sendValidCode',
						data: data,
						success:function(result){
							if(result.success){
								alert('Please check email to get the code');
							}
						},
						error:function(jqXHR, textStatus, errorThrown){}
					});
				});
            </jq:jquery>
		</g:form>
	</div>
</body>

</html>
